package com.wg.controller;

import com.alibaba.edas.acm.ConfigService;
import com.wg.model.ShowContent;
import com.wg.result.BasePageData;
import com.wg.result.ResponseResult;
import com.wg.service.EsService;
import com.wg.util.LogUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by mc on 18/11/2.
 * https://edas.qtshe.com/diamond-server/config.co?
 */
@Api(description = "es")
@RestController
@RequestMapping("/es")
public class EsController {

    @Autowired
    private EsService esService;

    /**
     * 获取配置
     * @return
     */
    @ApiOperation("获取配置")
    @PostMapping(value = "/save")
    public ResponseResult<String> save(){

        try {
            ShowContent showContent = new ShowContent();
            showContent.setId(3L);
            showContent.setShowContent("初中 宋·李清照 常记溪亭日暮，沉醉不知归路，兴尽晚回舟，误入藕花深处。争渡，争渡");
            showContent.setShowTag("诗词");
            showContent.setTitle("《浣溪沙》");
            esService.save(showContent);
            return ResponseResult.toSuccess();
        } catch (Exception e) {
            return ResponseResult.toFail();
        }

    }


    /**
     * 获取配置
     * @return
     */
    @ApiOperation("get one")
    @PostMapping(value = "/getById")
    public ResponseResult<ShowContent> getById(Long id){
        try {
            return ResponseResult.toSuccess(esService.getById(id));
        } catch (Exception e) {
            return ResponseResult.toFail();
        }
    }


    /**
     * 获取配置
     * @return
     */
    @ApiOperation("query")
    @PostMapping(value = "/query")
    public ResponseResult<List<ShowContent>> query(String title){
        try {
            return ResponseResult.toSuccess(esService.query(title));
        } catch (Exception e) {
            return ResponseResult.toFail();
        }
    }


    /**
     * 获取配置
     * @return
     */
    @ApiOperation("page")
    @PostMapping(value = "/page")
    public ResponseResult<BasePageData<ShowContent>> page(String title){
        try {
            return ResponseResult.toSuccess(esService.page(title));
        } catch (Exception e) {
            LogUtil.getDefaultLog().info("获取分页信息:{}",e);
            return ResponseResult.toFail();
        }
    }
}
